package casts
{
   import flash.display.MovieClip;
   import flash.events.Event;
   import flash.utils.Dictionary;

   /**
    * A MovieClip that can be paused by calling DEF.pause() and resumed by calling DEF.resume() method.
    * @author     cjboy | cjboy1984@gmail.com
    * @usage
    * // make it pause
    * DEF.pause();
    * // make it resume
    * DEF.resume();
    */
   public class GenericPauseResumeMovieClip extends MovieClip
   {
      private static var all:Array = new Array();

      /* constructor */
      public function GenericPauseResumeMovieClip()
      {
         addEventListener(Event.ADDED_TO_STAGE, onAdd);
         addEventListener(Event.REMOVED_FROM_STAGE, onRemove);
      }

      // --------------------- LINE ---------------------

      // 停止所有的影片
      public static function stopAll():void
      {
         for (var i:int = 0; i < all.length; ++i)
         {
            MovieClip(all[i]).stop();
         }
      }

      // 播放所有的影片
      public static function playAll():void
      {
         for (var i:int = 0; i < all.length; ++i)
         {
            MovieClip(all[i]).play();
         }
      }

      // ################### protected ##################

      // #################### private ###################

      private function onAdd(e:Event):void
      {
         // 加到all裡
         if (-1 == all.indexOf(this))
         {
            all.push(this);
            //trace('add >>', all.length);
         }
      }

      private function onRemove(e:Event):void
      {
         // 從all裡移除
         var ii:int = all.indexOf(this);
         if (-1 == ii)
         {
            all.splice(ii, 1);
            //trace('remove <<', all.length);
         }
      }

      // --------------------- LINE ---------------------

   }

}